package org.sixlab.googlecode;
/**
 * 
 * @author HundredKG
 * 
 */
public class MySort {
	public static void QuickSort(int[] a) {
		int key = a[0];
		int low = 0;
		int high = a.length - 1;
		while (low < high) {
			while ((a[high] >= key) && (low < high)) {
				high--;
			}
			a[low] = a[high];

			System.out.println("1:" + low + " " + high);
			for (int i = 0; i < a.length; i++) {
				System.out.print(a[i] + "\t");
			}
			System.out.println();
			while ((a[low] < key) && (low < high)) {
				low++;
			}
			a[high] = a[low];

			System.out.println("2:" + low + " " + high);
			for (int i = 0; i < a.length; i++) {
				System.out.print(a[i] + "\t");
			}
			System.out.println();
		}
		a[low] = key;
	}

	public static void main(String[] args) {
		int[] a = new int[] { 52, 2, 4, 423, 2, 42, 55, 67, 3, 5, 24, 664, 243 };
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + "\t");
		}
		System.out.println();
		System.out.println("------------------------");
		QuickSort(a);
		System.out.println("------------------------");
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + "\t");
		}
	}

}
/* 
52      2       4       423     2       42      55      67      3       5       24      664     243
------------------------
1:0 10
24      2       4       423     2       42      55      67      3       5       24      664     243
2:3 10
24      2       4       423     2       42      55      67      3       5       423     664     243
1:3 9
24      2       4       5       2       42      55      67      3       5       423     664     243
2:6 9
24      2       4       5       2       42      55      67      3       55      423     664     243
1:6 8
24      2       4       5       2       42      3       67      3       55      423     664     243
2:7 8
24      2       4       5       2       42      3       67      67      55      423     664     243
1:7 7
24      2       4       5       2       42      3       67      67      55      423     664     243
2:7 7
24      2       4       5       2       42      3       67      67      55      423     664     243
------------------------
24      2       4       5       2       42      3       52      67      55      423     664     243 */
